<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let obj = {
            name : '张三',
            obj1:{
                myname : '李四'
            }
        }
        // console.log(obj.age);//undefined
        // console.log(obj.obj1.age);//undefined
        // console.log(obj.obj2.age);//
        
        //可选操作符
        // if(typeof obj.obj2 !== "undefined"){
        //     console.log(obj.obj2.age);
        // }

        // ES6进行了缩写
        // ?判断一下有没有
            console.log(obj?.obj1);
            console.log(obj?.obj1?.name);
            console.log(obj?.obj1?.myname);

            // 2.空合并运算符 ??
            function fn(a,b){
                // ||会把0,''当成false处理
                // var a = a||1;
                // var b = b||2;

                // ??会把0,''当成true处理
                var a = a??1
                var b = b??2
                console.log(a,b);
            }
            fn(0,'')
    </script>
</body>
</html>